package com.example.statemachine;

public class StatesEvents {

    public enum State {
        START,
        NEW,
        PENDING_DOC,
        DOCUMENT_UPLOADED,
        SUBMITTED,
        INVALID,
        PENDING_DOC_CHOICE
    }

    public enum Event {

        INITIATE("initiate", State.START),
        UPLOAD_DOC("uploadDoc", State.DOCUMENT_UPLOADED),
        DELETE_DOC("deleteDoc", State.PENDING_DOC),
        SUBMIT_APPLICATION("submitApplication", State.SUBMITTED),
        INVALID_EVENT("invalid_event", State.INVALID);

        private final String value;

        private State state;

        Event(String value, State state) {
            this.value = value;
            this.state = state;
        }

        public static Event fromValue(String value) {
            Event[] values = Event.values();
            Event matchedEvent = Event.INVALID_EVENT;
            if (null != value) {
                for (Event event : values) {
                    if (event.value.equalsIgnoreCase(value)) {
                        matchedEvent = event;
                        break;
                    }
                }
            }
            return matchedEvent;
        }

        public String value() {
            return this.value;
        }

        public State state() {
            return this.state;
        }

        @Override
        public String toString() {
            return this.value + " - " + this.state.name();
        }
    }

}
